//
//  CheckOrderCell.m
//  mendianjieke
//
//  Created by 响当当 on 9/4/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "CheckOrderCell.h"

@interface CheckOrderCell()
@property (nonatomic, strong)UILabel *waresLabel;
@property (nonatomic, strong)UILabel *waresCountLabel;
@property (nonatomic, strong)UILabel *priceLabel;
@end

@implementation CheckOrderCell

- (UILabel *)waresLabel
{
    if (!_waresLabel)
    {
        _waresLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus,15*kUIScaleBasePlus,200*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentLeft
                                           textClor:LCHexColor(0x282828)
                                           textFont:14*kUIScaleBasePlus];
        _waresLabel.numberOfLines = 0;
        _waresLabel.text = @"灯泡5瓦led灯泡";
    }
    return _waresLabel;
}

- (UILabel *)waresCountLabel
{
    if (!_waresCountLabel)
    {
        _waresCountLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.waresLabel.frame)+20*kUIScaleBasePlus,15*kUIScaleBasePlus,20*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentCenter
                                           textClor:LCHexColor(0x282828)
                                           textFont:13*kUIScaleBasePlus];
        _waresCountLabel.text = @"1";
    }
    return _waresCountLabel;
}

- (UILabel *)priceLabel
{
    if (!_priceLabel)
    {
        _priceLabel = [Utilties creatLabelWithFrame:CGRectMake(SCREEN_WIDTH-15*kUIScaleBasePlus-80*kUIScaleBasePlus,15*kUIScaleBasePlus,80*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentRight
                                           textClor:LCHexColor(0x282828)
                                           textFont:13*kUIScaleBasePlus];
        _priceLabel.text = @"¥100.00";
    }
    return _priceLabel;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.contentView.backgroundColor = LCHexColor(0xFAFAFA);
        [self.contentView addSubview:self.waresLabel];
        [self.contentView addSubview:self.waresCountLabel];
        [self.contentView addSubview:self.priceLabel];

    }
    return self;
}

- (void)setModel:(CheckOrderModel *)model
{
    _model = model;
    
    self.waresLabel.text = model.content;
    self.waresCountLabel.text =  model.count;
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",model.price];
}

+ (CGFloat)heightWithModel:(CheckOrderModel *)model
{
    NSString *string = model.content;
    
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
    
    NSRange allRange = [string rangeOfString:string];
    
    [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:allRange];
    
    [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor]range:allRange];
    
    CGFloat titleHeight;
    
    NSStringDrawingOptions options =  NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    
    // 获取label的最大宽度
    CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(SCREEN_WIDTH, CGFLOAT_MAX)options:options context:nil];
    
    titleHeight = ceilf(rect.size.height);
    
    return titleHeight + 25*kUIScaleBasePlus; // 动态高度 + 静态高度
}
@end
